<?php

namespace app\admin\controller\file;

use app\admin\controller\AdminController;
use app\admin\service\file\FileService;
use app\admin\validate\file\FileValidate;
use think\response\Json;

/**
 * 文件管理
 */
class File extends AdminController
{

    /**
     * 文件列表
     * @return Json
     */
    public function lists()
    {
        return $this->data(FileService::getFileList());
    }


    /**
     * 文件移动
     * @return Json
     */
    public function move()
    {
        $params = (new FileValidate())->post()->checkParam("move");
        $result = FileService::move($params);
        if (true === $result) {
            return $this->success([],'移动成功');
        } else {
            return $this->error('移动失败');
        }
    }


    /**
     * 重命名文件
     * @return Json
     */
    public function rename()
    {
        $params = (new FileValidate())->post()->checkParam('rename');
        $result = FileService::rename($params);
        if (true === $result) {
            return $this->success([],'重命名成功');
        } else {
            return $this->error('重命名失败');
        }
    }


    /**
     * 删除文件
     * @return Json
     */
    public function delete()
    {
        $params = (new FileValidate())->delete()->checkParam('delete');
        $result = FileService::delete($params);
        if (true === $result) {
            return $this->success([],'删除成功');
        } else {
            return $this->error('删除失败');
        }
    }


    /**
     * 文件分类列表
     * @return Json
     */
    public function listCate()
    {
        return $this->data(FileService::getCateFileList());
    }


    /**
     * 添加文件分类
     * @return Json
     */
    public function addCate()
    {
        $params = (new FileValidate())->post()->checkParam('addCate');
        $result = FileService::addCate($params);
        if (true === $result) {
            return $this->success([],'添加成功');
        } else {
            return $this->error('添加失败');
        }
    }


    /**
     * 编辑文件分类
     * @return Json
     */
    public function editCate()
    {
        $params = (new FileValidate())->post()->checkParam('editCate');
        $result = FileService::editCate($params);
        if (true === $result) {
            return $this->success([],'编辑成功');
        } else {
            return $this->error('编辑失败');
        }
    }


    /**
     * 删除文件分类
     * @return Json
     */
    public function delCate()
    {
        $params = (new FileValidate())->delete()->checkParam('id');
        $result = FileService::delCate($params);
        if (true === $result) {
            return $this->success([],'删除成功');
        } else {
            return $this->error('删除失败');
        }
    }
}